package ac.svn.accesscontrol.ui.panel;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.RadialGradientPaint;
import java.awt.RenderingHints;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.Point2D;
import java.awt.geom.RoundRectangle2D;

import javax.swing.JToolBar;

public class RToolbar extends JToolBar {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int xLoc = 0 , yLoc =  0;

	Color light = new Color(204,255,204);//CAE1FF
	Color dark  = new Color(204,153,255); //A2B5CD	

	public RToolbar() {
		addPainter();
	}

	public RToolbar(int arg0) {
		super(arg0);
		addPainter();
	}

	public RToolbar(String arg0) {
		super(arg0);
		addPainter();
	}

	public RToolbar(String arg0, int arg1) {
		super(arg0, arg1);
		addPainter();
	}

	private void addPainter() {
		
		setLayout(new FlowLayout(FlowLayout.LEFT, 3, 0));
		
		addMouseListener(new MouseListener() {
			@Override
			public void mouseReleased(MouseEvent e) {
				repaint();
			}
			@Override
			public void mousePressed(MouseEvent e) {
				repaint();
			}
			@Override
			public void mouseExited(MouseEvent e) {
				//dark = dark.brighter();
				repaint();
			}
			@Override
			public void mouseEntered(MouseEvent e) {
				//dark = dark.darker();
				repaint();
			}
			@Override
			public void mouseClicked(MouseEvent e) {
			}
		});


		addMouseMotionListener(new MouseMotionListener() {
			@Override
			public void mouseMoved(MouseEvent e) {
				xLoc = e.getX();
				yLoc = e.getY();
				repaint();
			}
			@Override
			public void mouseDragged(MouseEvent e) {
			}
		});	
	}

	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);

		//xLoc = getWidth()/2;
		yLoc = 0;//getHeight();

		Graphics2D g2 = (Graphics2D) g;
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		Paint oldPaint = g2.getPaint();
		g2.setColor(Color.GREEN);
		Paint radical = new RadialGradientPaint(new Point2D.Double(xLoc,yLoc), getWidth()/4,
				new float[] { 0.0f, 0.5f ,1.0f },
				new Color[] {light.brighter(),dark,dark.darker()});
		g2.setPaint(radical);

		g2.fill(new RoundRectangle2D.Double(0,0,getWidth(),getHeight(),5,5));
		g2.setPaint(oldPaint);

	}

}
